<template>
  <codemirror
    class="code"
    ref="editScript"
    v-model="code.script"
    :options="cmOption"
  />
</template>

<script>
import { codemirror } from "vue-codemirror";

import "codemirror/lib/codemirror.css";
import "codemirror/theme/monokai.css";
import "codemirror/theme/panda-syntax.css";

require("codemirror/lib/codemirror");
require("codemirror/mode/javascript/javascript");

import "codemirror/addon/hint/show-hint.js";
import "codemirror/addon/hint/show-hint.css";
import "codemirror/addon/hint/javascript-hint.js";

import "codemirror/addon/fold/foldgutter.css";
import "codemirror/addon/fold/foldcode";
import "codemirror/addon/fold/foldgutter";
import "codemirror/addon/fold/brace-fold";
import "codemirror/addon/fold/comment-fold";

export default {
  components: {
    codemirror,
  },
  props: {
    code: {
      type: Object,
    },
  },
  data() {
    return {
      cmOption: {
        tabSize: 4,
        lineNumbers: true,
        line: true,
        indentWithTabs: true,
        smartIndent: true,
        autofocus: true,
        mode: "text/javascript",
        theme: "monokai",
        foldGutter: true,
        lineWrapping: true,
        gutters: [
          "CodeMirror-linenumbers",
          "CodeMirror-foldgutter",
          "CodeMirror-lint-markers",
        ],
      },
    };
  },
};
</script>
